// import Cookies from "js-cookie";

export function getToken() {
  // return Cookies.get("admin_token");
  const x = localStorage.getItem("admin_token");
  if (!x) return null;
  const { token, expires } = JSON.parse(x);
  if (new Date().getTime() > expires) {
    removeToken();
    setNickName("");
    return null;
  }
  return token;
}

export function setToken(token, expires) {
  // return Cookies.set("admin_token", token, { expires: new Date(new Date().getTime() + expires) });
  return localStorage.setItem("admin_token", JSON.stringify({ token, expires }));
}

export function removeToken() {
  // return Cookies.remove("admin_token");
  return localStorage.removeItem("admin_token");
}

export function setNickName(value) {
  return localStorage.setItem("nickname", value);
}

export function getNickName() {
  return localStorage.getItem("nickname");
}
